using System;
using System.Collections.Generic;

namespace Accounting.Library.Utility
{
    public class DieuKienNghiepVuEventArgs : EventArgs
    {
        #region Constant
        private static int PhuongThucThanhToanNgay = 1;
        private static int PhuongThucThanhToanCongNo_TienMat = 2;
        private static int PhuongThucThanhToanCongNo_ChuyenKhoan = 3;

        private static int LoaiTienTe_VND = 1;
        private static int LoaiTienTe_USD = 2;
        private static int LoaiTienTe_EUR = 3;

        private static int LoaiMuaSanPham_TN = 1;
        private static int LoaiMuaSanPham_NK = 2;
        #endregion

        #region Field
        private int phuongThucThanhToanId;
        private int loaiTienId;
        private bool laChiPhi;
        private int loaiMuaSanPhamId;
        private int loaiChungTuId;

        public DieuKienNghiepVuEventArgs()
        {
        }

        public DieuKienNghiepVuEventArgs(int? phuongThucThanhToan, int? loaiTien, bool laChiPhi, int loaiChungTu)
        {
            this.phuongThucThanhToanId = phuongThucThanhToan == null ? 0 : (int) phuongThucThanhToan;
            this.loaiTienId = loaiTien == null ? 0 : (int)loaiTien;
            this.laChiPhi = laChiPhi;
            this.loaiChungTuId = loaiChungTu == null ? 0 : (int)loaiChungTu;

            Initialized();
        }

        private void Initialized()
        {
            LocDanhMucTaiKhoan();
        }
        #endregion

        #region Property
        private bool ChuaThanhToan 
        {
            get 
            {
                return phuongThucThanhToanId != PhuongThucThanhToanNgay;
            }
        }

        private bool ThanhToanNgay
        {
            get
            {
                return phuongThucThanhToanId == PhuongThucThanhToanNgay;
            }
        }

        private bool LoaiTien_NoiTe
        {
            get
            {
                return loaiTienId == LoaiTienTe_VND;
            }
        }

        private bool LoaiTien_NgoaiTe
        {
            get
            {
                return loaiTienId != LoaiTienTe_VND;
            }
        }

        private bool LoaiMuaSanPham_TrongNuoc
        {
            get
            {
                return loaiMuaSanPhamId == LoaiMuaSanPham_TN;
            }
        }

        private bool LoaiMuaSanPham_NhapKhau
        {
            get 
            {
                return loaiMuaSanPhamId == LoaiMuaSanPham_NK;
            }
        }

        public List<string> DanhMucTaiKhoanCoChiTiet { get; private set; }
        public List<string> DanhMucTaiKhoanNoChiTiet { get; private set; }
        public List<string> DanhMucTaiKhoanCoThue { get; private set; }
        public List<string> DanhMucTaiKhoanNoThue { get; private set; }
        #endregion

        #region Loc dieu kien nghiep vu
        private void LocDanhMucTaiKhoan() 
        {
            if (loaiChungTuId == BusinessConfiguration.Configuration.LoaiChungTuId_BSP_BanDichVu)
                LocDanhMucTaiKhoan_BSP_BanDichVu();
            else if (loaiChungTuId == BusinessConfiguration.Configuration.LoaiChungTuId_MSP_MuaDichVu)
                LocDanhMucTaiKhoan_MSP_MuaDichVu();
        }

        private int LocDKNV_BSP_BanDichVu()
        {
            if (ChuaThanhToan && LoaiTien_NoiTe && laChiPhi == true)
                return 1;
            else if (ChuaThanhToan && LoaiTien_NoiTe && laChiPhi == false)
                return 2;
            else if (ChuaThanhToan && LoaiTien_NgoaiTe && laChiPhi == true)
                return 3;
            else if (ChuaThanhToan && LoaiTien_NgoaiTe && laChiPhi == false)
                return 4;
            else if (ThanhToanNgay && LoaiTien_NoiTe && laChiPhi == true)
                return 5;
            else if (ThanhToanNgay && LoaiTien_NoiTe && laChiPhi == false)
                return 6;
            else if (ThanhToanNgay && LoaiTien_NgoaiTe && laChiPhi == true)
                return 7;
            else if (ThanhToanNgay && LoaiTien_NgoaiTe && laChiPhi == false)
                return 8;
            else
                return 0;
        }

        private int LocDKNV_MSP_MuaDichVu()
        {
            if (ChuaThanhToan && LoaiTien_NoiTe && laChiPhi == true)
                return 1;
            else if (ChuaThanhToan && LoaiTien_NoiTe && laChiPhi == false)
                return 2;
            else if (ChuaThanhToan && LoaiTien_NgoaiTe && laChiPhi == true)
                return 3;
            else if (ChuaThanhToan && LoaiTien_NgoaiTe && laChiPhi == false)
                return 4;
            else if (ThanhToanNgay && LoaiTien_NoiTe && laChiPhi == true)
                return 5;
            else if (ThanhToanNgay && LoaiTien_NoiTe && laChiPhi == false)
                return 6;
            else if (ThanhToanNgay && LoaiTien_NgoaiTe && laChiPhi == true)
                return 7;
            else if (ThanhToanNgay && LoaiTien_NgoaiTe && laChiPhi == false)
                return 8;
            else
                return 0;
        }

        private void LocDanhMucTaiKhoan_MSP_MuaDichVu()
        {
            DanhMucTaiKhoanNoChiTiet = new List<string> { "1423", "1428", "2423", "2428", "6237", "6238", "6277", "6278", "6417", "6418", "6427", "6428", "811", "635" };
            DanhMucTaiKhoanCoChiTiet = new List<string> { "331" };
            DanhMucTaiKhoanNoThue = new List<string> { "1331" };
            DanhMucTaiKhoanCoThue = new List<string> { "331" };
        }

        private void LocDanhMucTaiKhoan_BSP_BanDichVu()
        {
            if (phuongThucThanhToanId == PhuongThucThanhToanNgay) 
            {
                DanhMucTaiKhoanNoChiTiet = new List<string> { "1423", "1428", "2423", "2428", "6237", "6238", "6277", "6278", "6417", "6418", "6427", "6428", "811", "635" };
                DanhMucTaiKhoanCoChiTiet = new List<string> { "111" };
                DanhMucTaiKhoanNoThue = new List<string> { "13311" };
                DanhMucTaiKhoanCoThue = new List<string> { "111" };
            }
            else
            {
                DanhMucTaiKhoanNoChiTiet = new List<string> { "1423", "1428", "2423", "2428", "6237", "6238", "6277", "6278", "6417", "6418", "6427", "6428", "811", "635" };
                DanhMucTaiKhoanCoChiTiet = new List<string> { "131" };
                DanhMucTaiKhoanNoThue = new List<string> { "13311" };
                DanhMucTaiKhoanCoThue = new List<string> { "131" };
            }
        }
        #endregion
    }
}